import {AsyncStorage} from 'react-native'
import { observable, configure, action, computed , runInAction} from 'mobx'
import Home from '../service/Home'
configure({enforceActions: 'observed'})

class Config {
    constructor(){
        this.initConfig()
    }
    @observable config = {
        banner: [],
        nav: [],
        notice: '',
        module: [],
        customer:{

        },
    }

    @action fetchHomeConfig= () => {
        return Home.fetchHomeData().then((res)=> {
            runInAction(()=> {
                this.config = res.data
                AsyncStorage.setItem('config', JSON.stringify(res.data))
            })
        })
    }
    async initConfig() {
        let config = await AsyncStorage.getItem('config')
        if(config){
            runInAction(()=> {
                this.config = JSON.parse(config)
            })
        }

    }
}

export default Config